import redis
import time

if __name__ == '__main__':
    client = redis.StrictRedis(
        host="192.168.189.137",
        port=6379,
        db=0
    )
    # 0 号数据库准备就绪 开始行动
    client.flushdb()
#     字符串的相关操作
# 增
    client.set("str1", "String1")
# 增加多个  以字典的格式进行添加
    client.mset({"str2": "String2", "str3": "String3"})
# 删除
    client.delete("str1")
# 修改
    client.set("str2", "String22")
# 查
    print(client.get("str2"), client.get("str3"))
# 查询多个
    print(client.mget("str2", "str3"))
# 追加
    client.append("str3", "3")
    print(client.get("str3"))
# 设置key有效时间
    client.setex("str3", 10, "value")
# 查看剩余有效时间
    time.sleep(3)
    print(client.ttl("str3"))
    print(client.keys())


